package org.cfg;

import com.sojoys.artifact.build.data.base.BaseCfg;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import java.util.ArrayList;
/**
 * 事件条件
 */
public class EventConditionCfg extends BaseCfg<EventConditionCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "event_condition";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.EventConditionCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 4;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","事件ID","是否需要检查历史数据","备注",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","event_id","history","remark",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","eventId","history","remark",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,278118624,926934164,-934624384,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","int","boolean","String",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,Integer.class,Boolean.class,String.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 事件ID
	 */
	private int eventId;
	
	/**
	 * 是否需要检查历史数据
	 */
	private boolean history;
	
	/**
	 * 备注
	 */
	private String remark;
	
	
	
	public static EventConditionCfg builder() {
		EventConditionCfg eventConditionCfg = new EventConditionCfg();
		return eventConditionCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 事件ID
	 */
	public int getEventId() {
		return eventId;
	}
	
	/**
	 * 是否需要检查历史数据
	 */
	public boolean getHistory() {
		return history;
	}
	
	/**
	 * 备注
	 */
	public String getRemark() {
		return remark;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.eventId;
        values[2] = this.history;
        values[3] = this.remark;
        return values;
	}
	
	protected EventConditionCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.eventId = (int)vals[1];
		this.history = (boolean)vals[2];
		this.remark = (String)vals[3];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.eventId);
        map.put(keys[2], this.history);
        map.put(keys[3], this.remark);
        return map;
    }
    
    protected EventConditionCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.eventId = (int)map.get(keys[1]);
   		this.history = (boolean)map.get(keys[2]);
   		this.remark = (String)map.get(keys[3]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.eventId);
        obj.put(keys[2], this.history);
        obj.put(keys[3], this.remark);
        return obj;
    }
    
    protected EventConditionCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.eventId = obj.getIntValue(keys[1]);
	    this.history = obj.getBooleanValue(keys[2]);
	    this.remark = obj.getString(keys[3]);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.eventId);
	    byteBuf.writeBoolean(this.history);
	    byteBuf.writeString(this.remark);
    }
	
	protected EventConditionCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.eventId = byteBuf.readInt(null);
	    this.history = byteBuf.readBoolean(null);
	    this.remark = byteBuf.readString(null);
	    return this;
	}
	
	public EventConditionCfg deepCopy(){
		EventConditionCfg eventConditionCfg = null;
		try {
			eventConditionCfg = (EventConditionCfg) super.clone();
			return eventConditionCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return eventConditionCfg;
	}
//自定义内容起始位置
//自定义内容结束位置
}
